﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SSDPNET;
using SSDPNET.DataCore;
using ATEC.ATDataCoreNET;
using SZEWAlignmentNet.AlignmentInterface;

namespace DoModelExample
{
    public class AttachAlignment
    {
        /// <summary>
        /// 激活视口
        /// </summary>
        /// <param name="viewIndex"></param>

        private static void ActiveView(int viewIndex)
        {
            IndexedViewSet viewSet = IViewManager.GetActiveViewSet();
            int nCurrentNum = viewSet.GetSelectedView();
            if (nCurrentNum != viewIndex)
            {
                IndexedViewport vp = viewSet.GetViewport(viewIndex);
                viewSet.SetSelectedView(vp, true, true);
            }
           
        }

        /// <summary>
        /// 参考路线
        /// </summary>
        public static void AttachmentAlignment()
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Filter = "db File (*.db)|*.db";
            dialog.Title = "请打开路线项目文件";

            if (DialogResult.OK != dialog.ShowDialog())
                return;

            string filePath = System.IO.Path.GetFullPath(dialog.FileName);

            ATProject masterATProject = ATObjFuncs.ProjectObjGetMasterProject();
            // 参考平面
            {

                ATSceneRef horizontalScene = SZEWAlignmentInterface.GetHoriScene(masterATProject);
                ViewManager.ActiveView(ViewIndex.ViewIndex_Horizon);
                ATDocMoniker atDoc = ATDocMoniker.CreateFromFileName(dialog.FileName, filePath);
                ATAttachment attachment = horizontalScene.CreateATAttachment(atDoc, horizontalScene.GetATScene().SceneName);
                attachment.WriteToScene(false);
             
                ViewManager.FitView();


            }
            // 参考空间
            {
                ATSceneRef spatialScene = SZEWAlignmentInterface.GetSpatialScene(masterATProject);
                ViewManager.ActiveView(ViewIndex.ViewIndex_Spatial);
                ATDocMoniker atDoc = ATDocMoniker.CreateFromFileName(dialog.FileName, filePath);
                ATAttachment attachment = spatialScene.CreateATAttachment(atDoc, spatialScene.GetATScene().SceneName);
                attachment.WriteToScene(false);           
                ViewManager.FitView();

            }
        }
    }
}
